package com.atguigu.java8.annotation;

import org.junit.Test;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * 重复注解与类型注解
 */
public class TestAnnotation {

    @MyAnnotation("repeat")
    @MyAnnotation("annotations")
    public void show(@MyAnnotation("name") String name) {
    }

    @Test
    public void test1() throws Exception {
        Class<TestAnnotation> testAnnotationClass = TestAnnotation.class;
        Method method = testAnnotationClass.getMethod("show", String.class);

        MyAnnotation[] myAnnotations = method.getAnnotationsByType(MyAnnotation.class);

        for (MyAnnotation myAnnotation : myAnnotations) {
            System.out.println(myAnnotation.value());
        }

        System.out.println("--------------------------------------------------------");

        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        for (Annotation[] parameterAnnotation : parameterAnnotations) {
            for (Annotation annotation : parameterAnnotation) {
                String value = ((MyAnnotation) annotation).value();
                System.out.println(value);
            }
        }
    }

}
